package com.ruoyi.web.shopping.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.web.shopping.entity.Prices;
import com.ruoyi.web.shopping.entity.Products;
import com.ruoyi.web.shopping.service.PricesService;
import com.ruoyi.web.shopping.service.ProductsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/prices")
@Slf4j
@Api(tags = "价格相关接口")
public class PricesController {
    @Autowired
    private PricesService pricesService;

    /**
     * 查询价格
     *
     * @param id
     * @return
     */
    @GetMapping("/select/{id}")
    @ApiOperation("查询价格")
    public R<Prices> selectById(@PathVariable String id) {
        log.info("查询价格id为{}", id);
        Prices prices = pricesService.selectById(id);
        return R.ok(prices);
    }

    /**
     * 修改价格
     *
     * @param prices
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改价格")
    public R<String> update(@RequestBody Prices prices) {
        log.info("修改价格为：{}", prices);
        pricesService.update(prices);
        return R.ok("修改成功");
    }

    /**
     * 删除价格
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除价格")
    public R<String> deleteById(@PathVariable String id) {
        log.info("删除价格id为：{}", id);
        pricesService.deleteById(id);
        return R.ok("删除成功");
    }

    /**
     * 新增价格
     *
     * @param prices
     * @return
     */
    @PostMapping(value = "/save")
    @ApiOperation("新增价格")
    public R<String> save(@RequestBody Prices prices) {
        log.info("新增价格：{}", prices);
        pricesService.save(prices);
        return R.ok("新增成功");
    }
}
